events { worker_connections 1024; }

http {
    upstream flask_app {
        server flask1:5000;
        server flask2:5000;
        server flask3:5000;
    }

    server {
        listen 80;
        server_name flask;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl;
        server_name flask;

        ssl_certificate /etc/nginx/certs/flask.crt;
        ssl_certificate_key /etc/nginx/certs/flask.key;

        location / {
            proxy_pass http://flask_app;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

